import Vue from 'vue'
import {
    Loading
} from 'element-ui'

let instance = null;

Vue.prototype.$showLoading = function (msg) {
    if (window.loadingTimeOutId) {
        clearTimeout(window.loadingTimeOutId);
        window.loadingTimeOutId = null;
    }
    let options = {
        lock: true,
        background: 'rgba(0, 0, 0, 0.5)',
        text: '正在加载,请稍后...',
    };
    if (msg != null) {
        options.text = msg;
    }
    instance = Loading.service(options);

    /**
     * 最大Loading15秒钟
     * 记录该timeout Id
     * add by zyyang5
     */
    let timeLoadingId = setTimeout(() => {
        instance.close();
    }, 15 * 1000);
    window.loadingTimeOutId = timeLoadingId;
};

Vue.prototype.$closeLoading = function () {
    if (window.loadingTimeOutId) {
        clearTimeout(window.loadingTimeOutId);
        window.loadingTimeOutId = null;
    }

    if (instance) {
        instance.close();
    }
};
//指定挂载DOM加载方式
let contentLoading = null

Vue.prototype.$contentLoading = (dom, options = {  lock: true,   background: 'rgba(0, 0, 0, 0.5)',    text: '正在加载,请稍后...',}) => {
    options.target = dom
    contentLoading = Loading.service(options)
    console.log('loading')

}
Vue.prototype.$closeContentLoading = ()=>{
    contentLoading.close()
}

export default ({})